using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JGSY.CMS.LowCode.Platform.Domain.Entities.Base;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 文章内容管理实体
    /// 对应 articles 表，支持完整的CMS功能，包括SEO、标签、版本控制，支持多租户隔离
    /// </summary>
    [Table("articles")]
    public class Article : AuditableEntity, ITenantEntity
    {
        /// <summary>
        /// 租户ID
        /// 用于多租户数据隔离
        /// </summary>
        [Required]
        [StringLength(36)]
        public string TenantId { get; set; } = string.Empty;

        /// <summary>
        /// 文章标题
        /// </summary>
        [Required]
        [StringLength(255)]
        public string Title { get; set; } = string.Empty;
        
        /// <summary>
        /// 文章别名/URL slug
        /// </summary>
        [Required]
        [StringLength(255)]
        public string Slug { get; set; } = string.Empty;
        
        /// <summary>
        /// 文章摘要
        /// </summary>
        [StringLength(500)]
        public string? Summary { get; set; }
        
        /// <summary>
        /// 文章内容（富文本）
        /// </summary>
        [Column(TypeName = "text")]
        public string? Content { get; set; }
        
        /// <summary>
        /// 特色图片URL
        /// </summary>
        [StringLength(500)]
        public string? FeaturedImage { get; set; }
        
        /// <summary>
        /// 分类ID
        /// </summary>
        public long? CategoryId { get; set; }
        
        /// <summary>
        /// 标签列表（JSON格式存储）
        /// 如：["技术", "教程", "前端"]
        /// </summary>
        [Column(TypeName = "json")]
        public string? Tags { get; set; }
        
        /// <summary>
        /// 文章状态
        /// 0=草稿, 1=发布, 2=审核中, 3=已撤回, 4=归档
        /// </summary>
        public byte Status { get; set; } = 0;
        
        /// <summary>
        /// 版本号
        /// </summary>
        public int Version { get; set; } = 1;
        
        /// <summary>
        /// 发布时间
        /// </summary>
        public DateTime? PublishedAt { get; set; }
        
        /// <summary>
        /// 浏览次数
        /// </summary>
        public int ViewCount { get; set; } = 0;
        
        /// <summary>
        /// 点赞数
        /// </summary>
        public int LikeCount { get; set; } = 0;
        
        /// <summary>
        /// 评论数
        /// </summary>
        public int CommentCount { get; set; } = 0;
        
        /// <summary>
        /// 置顶权重（0=不置顶，数值越大权重越高）
        /// </summary>
        public int TopWeight { get; set; } = 0;
        
        /// <summary>
        /// 是否推荐
        /// </summary>
        public bool IsRecommended { get; set; } = false;
        
        /// <summary>
        /// 是否允许评论
        /// </summary>
        public bool AllowComments { get; set; } = true;
        
        /// <summary>
        /// SEO标题
        /// </summary>
        [StringLength(255)]
        public string? SeoTitle { get; set; }
        
        /// <summary>
        /// SEO关键词
        /// </summary>
        [StringLength(500)]
        public string? SeoKeywords { get; set; }
        
        /// <summary>
        /// SEO描述
        /// </summary>
        [StringLength(500)]
        public string? SeoDescription { get; set; }
        
        /// <summary>
        /// 自定义属性（JSON格式）
        /// 存储扩展字段和自定义数据
        /// </summary>
        [Column(TypeName = "json")]
        public string? CustomFields { get; set; }
        
        /// <summary>
        /// 排序权重
        /// </summary>
        public int SortOrder { get; set; } = 0;
        
        /// <summary>
        /// 语言代码
        /// </summary>
        [StringLength(10)]
        public string? LanguageCode { get; set; }
        
        /// <summary>
        /// 发布人ID
        /// </summary>
        public long? PublishedBy { get; set; }

        // 导航属性

        /// <summary>
        /// 租户导航属性
        /// </summary>
        public Tenant? Tenant { get; set; }

        /// <summary>
        /// 分类导航属性
        /// </summary>
        [ForeignKey(nameof(CategoryId))]
        public Category? Category { get; set; }
        
        /// <summary>
        /// 创建人导航属性
        /// </summary>
        [ForeignKey(nameof(CreatedBy))]
        public User? Creator { get; set; }
        
        /// <summary>
        /// 修改人导航属性
        /// </summary>
        [ForeignKey(nameof(UpdatedBy))]
        public User? Updater { get; set; }
        
        /// <summary>
        /// 发布人导航属性
        /// </summary>
        [ForeignKey(nameof(PublishedBy))]
        public User? Publisher { get; set; }
    }
}
